<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href='http://fonts.googleapis.com/css?family=Archivo+Narrow:400italic,700,700italic,400' rel='stylesheet' type='text/css'/>
<link rel="StyleSheet" type="text/css" href="style.css" media="screen" />
<script type="text/javascript" src="js/jquery-1.8.2.min.js">
</script>
<script type="text/javascript" src="js/jquery.bgpos.js"></script>
<script type="text/javascript" src="js/MainMenu.js"></script>
<script type="text/javascript" src="js/LightBox.js"></script>
<script type="text/javascript" src="js/validation.js"></script>
<link rel="StyleSheet" type="text/css" href="MenuStyle.css" media="screen" />
<title>Painting Page</title>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.gif" type="image/gif">
</head>

<body>
    <div id="header">
        <h1> Premier </h1>
        <h1> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;products </h1>
    </div>
    <div id="content">
	<cfset name = "" />
	<cfset bFileWritten = false />    	
        <div id="main">
            <div class="info">
				<cfif IsDefined("URL.product_id") >
                	                    
                	<cfquery name="getProd" datasource="fit1012" username="fit1012" password="fit1012">
                            select * from PP_PARTS where PART_NUMBER = '#URL.product_id#'
                	</cfquery>
					
					<!--- writes reviews the visitor submits--->
					<cfif IsDefined("FORM.review")>
						<cfset newReview="<p>#FORM.review#</p>" />
                        
                        <cfdirectory directory="#GetDirectoryFromPath( GetCurrentTemplatePath() )#/reviews/#getProd.PART_DESCRIPTION#/" name="fileCount">
                        
                        <cfset numberOfReviews ="#fileCount.RecordCount#" />
                        
                        <cffile action="write" file="#GetDirectoryFromPath( GetCurrentTemplatePath() )#/reviews/#getProd.PART_DESCRIPTION#/#numberOfReviews + 1#.txt" 
                            output="#FORM.review#" />
                        <cfset bFileWritten = true /> 
                    </cfif>

                    
                    <cfdirectory directory="#GetDirectoryFromPath( GetCurrentTemplatePath() )#/reviews/#getProd.PART_DESCRIPTION#/" name="fileCount">
                    
					<cfset numberOfReviews ="#fileCount.RecordCount#" />
						
					<cfset reviewText = "None submitted" />	
					<cfif numberOfReviews gt 0>
						<cffile action="read" file="#GetDirectoryFromPath( GetCurrentTemplatePath() )#/reviews/#getProd.PART_DESCRIPTION#/#RandRange(1, numberOfReviews)#.txt" variable="reviewText"/>
					</cfif>
					
                    <h1><cfoutput query="getProd">#PART_DESCRIPTION#</cfoutput></h1>
					<a href="images/<cfoutput query="getProd">#PART_DESCRIPTION#</cfoutput>.jpg" title="<cfoutput query="getProd">#PART_DESCRIPTION#</cfoutput> by <cfoutput query="getProd">#ITEM_CLASS#</cfoutput>" rel="LightBox" >
                    <img src="images/thumbnails/<cfoutput query="getProd">#PART_DESCRIPTION#</cfoutput>_s.jpg" 
                    	alt="<cfoutput query="getProd">#PART_DESCRIPTION#</cfoutput>"/>
                    </a>
                    <p>
                    Name: <cfoutput query="getProd">#PART_DESCRIPTION#</cfoutput> <br />
                    Price: $<cfoutput query="getProd">#UNIT_PRICE#</cfoutput> <br />
                    Artist:   						
						<cfif GetProd.ITEM_CLASS is "AP">
                            Annie Potts
                        </cfif>
                        <cfif GetProd.ITEM_CLASS is "HW">
                            Herbert Wells
                        </cfif>
                        <cfif GetProd.ITEM_CLASS is "SG">
                            Sasha Goods
                        </cfif> <br />
                    Copies Left: <cfoutput>#GetProd.UNITS_ON_HAND#</cfoutput><br />
					Visitor Review: <cfoutput>#reviewText#</cfoutput> <br />
                    </p>
                </cfif>
            </div>
			<div class="info">
            	<h3>Review this piece</h3>
                <p>
                	Review this piece in 30 characters or less and have a chance at having your review featured on the site!
                </p>
                <cfif not IsDefined("FORM.review") >
                <form id="contact" method="post" action="" onsubmit="validateReviewForm(); return false;" onreset="resetForm();">
				
                    <div id="ContactErrorMsg" class="errorMsg"></div>
					
					<p>
                      <label for="review">Your Review:</label>
                      <textarea name="review" id="review" rows="5" cols="25" maxLength="30" onfocus="resetField(this,'Error');"></textarea>
                    </p>
                    <p>
                      <button type="submit">Send Review</button>
                      <button type="reset">Reset Form</button>
                    </p>
                </form>	
                <cfelseif bFileWritten is true>
                    <div class="confirmation"> Thank you for your review! </div>
                    <cfoutput>
                    <p>
                        #FORM.review# <br />
                    </p>
                    </cfoutput>
                </cfif>
            </div>	
        </div>
        <div id="navigation">
            <ul>
                <li class="blue"> 
                    <a href = "index.cfm"> Home 	</a>
                    <p class="subtext">The front page</p>
                </li>
                <li class="red">
                    <a href = "catalogue.cfm"> Catalogue	</a>
                    <p class="subtext">Our products</p>
                </li>
                <li class="green">
                    <a href = "about.cfm"> About	</a>
                    <p class="subtext">All about us</p>
                </li>
            </ul>
        </div>
    </div>
    <div id="footer">
        <p> 2012 &copy; Yati &amp; Nick </p>
    </div>
</body>
</html>